//
//  LBShuangyuCell.m
//  V-Learn
//
//  Created by Apple on 2018/12/27.
//  Copyright © 2018 yxk. All rights reserved.
//

#import "LBShuangyuCell.h"

@implementation LBShuangyuCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self setupUI];
    }
    return self;
}
+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *identifferCell = @"LBShuangyuCell";
    LBShuangyuCell *cell = [tableView dequeueReusableCellWithIdentifier:identifferCell];
    if (!cell) {
        cell = [[LBShuangyuCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifferCell];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }
    return cell;
}
- (void)clickScrollView{
    
}
- (void)setupUI{
    UIScrollView *scorllView = [[UIScrollView alloc] init];
    self.scorllView = scorllView;

    scorllView.userInteractionEnabled = YES;
    self.scorllView = scorllView;
    scorllView.frame = CGRectMake(15, 0, ScreenW, 133);
//    [self.contentView addSubview:scorllView];
    
    scorllView.showsVerticalScrollIndicator = NO;
    scorllView.showsHorizontalScrollIndicator = NO;
    for (int i=0; i<self.dataArray.count; i++) {
        
        LBCourseOutputDTOListModel *model = self.dataArray[i];
        UIView *smallView = [[UIView alloc] init];
        smallView.userInteractionEnabled = YES;
        
        smallView.layer.cornerRadius = 8;
        smallView.layer.masksToBounds = YES;
       UIButton *courseButton = [[UIButton alloc] init];
        self.courseButton = courseButton;
//        [btn setBackgroundImage:[UIImage imageNamed:@"small_place_yf"]];
//        [btn setImage:[UIImage imageNamed:@"kaifeng"] forState:UIControlStateNormal];
        smallView.backgroundColor = [UIColor clearColor];
        
        smallView.frame = CGRectMake(160*i, 0, 150, 90);
//        NSLog(@"%@",model.courseImage);
//        NSLog(@"%@",Public_URL);
        NSString *url = [NSString stringWithFormat:@"%@%@",Public_URL,model.courseImage];
        [courseButton sd_setImageWithURL:[NSURL URLWithString:url] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"wk_list_bgimg"]];
        courseButton.tag = i+666;
        courseButton.userInteractionEnabled = YES;
        courseButton.layer.cornerRadius = 8;
        courseButton.layer.masksToBounds = YES;
        [courseButton addTarget:self action:@selector(tapCourseBtn:) forControlEvents:UIControlEventTouchUpInside];
        [smallView addSubview:courseButton];
        [courseButton makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.bottom.mas_equalTo(0);
        }];
        [scorllView addSubview:smallView];
        
        UILabel *label = [UILabel labelWithText:@"" andTextColor:rgb(51,51,51) andName:nil andFontSize:14];
        label.text = model.courseName;
        [scorllView addSubview:label];
        [label makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(smallView.mas_bottom).mas_equalTo(10);
            make.left.mas_equalTo(smallView.mas_left);
        }];
    }
    scorllView.contentSize = CGSizeMake((150*self.dataArray.count)+(10*(self.dataArray.count+1)), 133);//
    [self.contentView addSubview:scorllView];

    
}
- (void)tapCourseBtn:(UIButton *)sender{
    if (self.delegate && [self.delegate respondsToSelector:@selector(clilkLBShuangyuCellBtn:WithArray:)]) {
        [self.delegate clilkLBShuangyuCellBtn:sender WithArray:self.dataArray];
    }
}
- (void)setDataArray:(NSMutableArray *)dataArray{
    _dataArray = dataArray;
    
    [self.scorllView removeFromSuperview];
    [self setupUI];
}

- (void)setModel:(LBHomeCoureseModel *)model{
    _model = model;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
